package com.app.service;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Bitmap;

import com.app.data.LineItem;
import com.app.data.ScenicItem;

public class ScenicService extends BaseService {
	String urlString = url_base + "/api/tickets.php?htype=2";
	public ScenicService(HttpCallBack callBack) {
		super(callBack);
	}

	@Override
	protected String doInBackground(String... params) {
		return connectUrl(urlString);
	}
	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		 try 
		 {
	   		 ArrayList<ScenicItem> list = new ArrayList<ScenicItem>();
	   		 JSONObject object = new JSONObject(result);
	   		 JSONArray array = object.getJSONArray("data");
	   		 int len = array.length();
	   		 for (int i = 0; i < len; i++) {
	   			JSONObject itemObj = array.getJSONObject(i);
	   			ScenicItem item = new ScenicItem();
	   			int arcid = itemObj.getInt("aid");
	   			item.setSenicName("景点编号"+arcid);
	   			item.setSenicIntro(itemObj.getString("title"));
	   			String fx = itemObj.getString("fx");
	   			String fxs[] =   fx.split("\\|");
	   			item.setSenicPrice("￥  "+fxs[2]);
	   			item.setSenicSubject(itemObj.getString("keywords"));
	   			String imgUrl = url_base +  itemObj.getString("litpic");
	  		 	Bitmap bitmap = BitmapUtil.getNetBitmap(imgUrl);
	  		 	item.setIconbitmap(bitmap);
	  		 	item.setHtmlContent(itemObj.getString("jqjs"));
	  		 	list.add(item);
	   		 }
	   		 callback.ticketFinishLoad(0, list);
	   	}catch (JSONException e)
	   	{
			e.printStackTrace();
			callback.ticketFinishLoad(-1,  new ArrayList<ScenicItem>());
	   	}
	}

}
